﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using EF_Model;
using Moq;
using System;
using System.Data.Objects;

namespace EF_Tests
{
    [TestClass]
    public class UnitOfWork_SaveChanges_Logic_Test
    {
        /// <summary>
        /// Useful when the Repository/UnitOfWork.Save contains any validation/logic along with 
        /// Context.SaveChanges (requires to be virtual if Mock Framework is used) method.
        /// </summary>
        [TestMethod]
        public void UnitOfWork_SaveChanges_Returns_Success_When_Save_Changes_Returns_Greater_Than_Zero()
        {
            Mock<DatabaseContext> dbContext = new Mock<DatabaseContext>();
            UnitOfWork unitOfWork = new UnitOfWork(dbContext.Object);
            dbContext.Setup(db => db.SaveChanges()).Returns(1);
            bool result = unitOfWork.Commit();
            Assert.IsTrue(result);
        }
    }
}
